#include<iostream>
#include<map>
#include<cstring>
using namespace std;
typedef long long LL;
#define int long long 
const int N = 5e3 + 10, M = N * 2;
int h[N], e[M], ne[M], idx;
int n, k;
int sz[N], f[N];
int ans;
void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

void dfs(int u)
{
	sz[u] = 1;
	//cout<<"u=="<<u<<endl;
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		dfs(j);
		sz[u] += sz[j];
	}
	f[0] = 1;
	for (int i = 1; i <= n; i++)f[i] = 0;
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		for (int k = sz[u] - 1; k >= sz[j]; k--) {
			f[k] |= f[k - sz[j]];
		}
	}
	int res = 0;
	for (int i = 1; i < sz[u]; i++) {
		if (!f[i])continue;
		res = max(res, i * (sz[u] - i - 1));
	}
	//cout<<"res=="<<res<<endl;
	ans += res;
}
signed main()
{
	cin >> n;
	memset(h, -1, sizeof(h));
	for (int i = 2; i <= n; i++) {
		int x;
		cin >> x;
		add(x, i);
	}
	dfs(1);
	cout << ans << endl;
	return 0;
}